﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using App;
using Domin;
using Microsoft.AspNetCore.Hosting;
using System.IO;
using Microsoft.EntityFrameworkCore;
using JwT;
using Microsoft.AspNetCore.Authorization;

namespace UL.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RolesController : ControllerBase
    {
        private readonly IRApp db;

        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="db"></param>
        public RolesController(IRApp db)
        {
            this.db = db;
        }
        /// <summary>
        /// 角色显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        //[Authorize]
        //[AllowAnonymous]
        public IActionResult BInd(int Pindex = 1, int Psize = 2)
        {
            var ls = db.RShow().AsQueryable();
            PageLists p = new PageLists();
            p.PCount = ls.Count();
            p.PList = ls.OrderBy(x => x.RId).Skip((Pindex - 1) * Psize).Take(Psize).ToList();
            return Ok(new { data = p, msg = "显示成功!" });
        }
        /// <summary>
        /// 角色权限添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult OAdd(RolePowers rolePowers)
        {
            db.RAdd(rolePowers);
            return Ok(new { data = 1, msg = "添加成功!" });
        }
        /// <summary>
        /// 角色菜单添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult MAdd(RoleMune roleMune)
        {
            db.MAdd(roleMune);
            return Ok(new { data = 1, msg = "添加成功!" });
        }
    }
}
